<?php
/**
 * Created by PhpStorm.
 * User: huangzikun
 * Date: 2018/4/19
 * Time: 17:09
 */
namespace Huangzikun\hawkeye_spider;

class LoadSpiderClass extends BaseClass
{
    private $filePath = "/proc/loadavg";
    public $spiderInfo;
    public $apiAddress;

    public function __construct($apiAddress)
    {
        parent::__construct($apiAddress);
    }

    public function grab()
    {
        $info = file_get_contents($this->filePath);
        if(!empty($info)){
            $info = str_replace("\n", "", $info);
            $tmp = explode(" ", $info);
            $process = explode("/", $tmp[3]);
            $this->spiderInfo = [
                'load_1min' => $tmp[0],
                'load_5min' => $tmp[1],
                'load_15min' => $tmp[2],
                'run_process' => $process[0],
                'all_process' => $process[1]
            ];
        }
    }
}